#include "bits/stdc++.h"

using namespace std;

const int N = 210;

int n,k,m;
int a[N], w[N][N];

int dp[N][N]; // dp[i][j]表示a[1...i]中，删掉了j个数，且a[i]还在的最优解

// dp[i][j] = max(dp[i][j-(i-k-1)]) + w[a[k]][a[i]]) k属于(1,i)
int main() {
    cin >> n >> k >> m;

    for (int i=1; i <= m; i++) cin >> a[i];
    for (int i=1; i <= n; i++) {
        for (int j=1; j <= n; j++) {
            cin >> w[i][j];
        }
    }
    
    memset(dp, 0xff, sizeof(dp));
    dp[1][0] = 0;

    for (int i=2; i<=m; i++) {
        for (int j=0; j<=k; j++) {
            for (int r=1; r<i; r++) {
                if (j>=i-r-1) {
                    int next = dp[r][j-(i-r-1)] + w[a[r]][a[i]];
                    dp[i][j] = max(dp[i][j], next);
                }
            }
        }
    }

    int ans = 0;
    for (int i=0; i<=k; i++) {
        ans = max(ans, dp[m][i]);
    }

    cout << ans << endl;
    return 0;
}